﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Test
{
	/// <summary>
	/// MainWindow.xaml 的交互逻辑
	/// </summary>
	public partial class MainWindow : Window
	{
		public MainWindow()
		{
			InitializeComponent();
		}

		private void Print_Click(object sender, RoutedEventArgs e)
		{
			PrintDialog dialog = new PrintDialog();

			double width = this.Table.ActualWidth;
			double height = this.Table.ActualHeight;

			System.Windows.Controls.Grid grid = new Grid();
			if (dialog.ShowDialog() == true)
			{

				//you can make your own precise calculation here
				Size pageSize = new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight);
				// sizing of the element.
				//this.Table.Measure(pageSize);
				//this.Table.Arrange(new Rect(0, 0, pageSize.Width, pageSize.Height));
				this.DockPanel.Children.Remove(this.Table);
				grid.Children.Add(this.Table);

				dialog.PrintVisual(grid, "Print Test");
			}
			if (grid.Children.Count == 0)
				return;
			grid.Children.Remove(this.Table);
			this.DockPanel.Children.Add(this.Table);


			//this.Table.InvalidateArrange();

			//this.Table.Arrange(new Rect(0, 0, double.NaN, double.NaN));
		}
	}
}
